package com.wx.fresh.user.service;

import com.wx.fresh.common.pojo.CUser;
import com.wx.fresh.common.util.CommonResult;
import com.wx.fresh.user.api.LoginFeignClient;
import com.wx.fresh.user.dto.CustomLoginDto;
import com.wx.fresh.user.dto.CustomRegisterDto;
import com.wx.fresh.user.mapper.CustomUserMapper1;
import lombok.Builder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Date;

/**
 * @author Dshzs月
 * @version 1.0.0
 * @ClassName LoginFeignClientImpl.java
 * @Description TODO
 * @createTime 2022年04月27日 18:31:00
 */
@RestController
@RequestMapping("login")
@Builder
public class LoginFeignClientImpl implements LoginFeignClient {

    @Autowired
    private CustomUserMapper1 customUserMapper;

    @Override
    @PostMapping("/registerUser")
    public int registerUser(CustomRegisterDto customRegisterDto) {
        CUser cUser = new CUser();
        cUser.setUserId(6L);
        cUser.setPhone("12345657885");
        cUser.setBirth(new Date(2020-2-22));
        cUser.setNikename("wo sni ");
        cUser.setSex(2);
        cUser.setCreateUser(6);
        cUser.setUpdateUser(6);
        BeanUtils.copyProperties(customRegisterDto,cUser);
        return customUserMapper.save(cUser);
    }

    @Override
    @PostMapping("customLogin")
    public CommonResult customLogin(CustomLoginDto customLoginDto) {

        CUser cUser = new CUser();
        BeanUtils.copyProperties(customLoginDto,cUser);
        return CommonResult.success(customUserMapper.findByUsernameAndPassword(cUser));
    }
}
